<?php

namespace app\model\main;

use linkphp\Application;
use linkphp\boot\Exception;

class Download
{

    public function push()
    {
        Application::db()->beginTransaction();
        try{
            $data['title'] = Application::input('post.title');
            $data['c_id'] = 1;
            $data['u_id'] = 2;
            $data['picture'] = '/static/img/lib/php.png';
            $data['leavel_id'] = Application::input('post.leavel');
            $data['price'] = Application::input('post.price');
            $data['post_time'] = date('Y-m-d H:i:s',time());
            $res['down_id'] = Application::db()->table('lp_download')
                ->insert($data);
            $res['content'] = Application::input('post.desc');
            $res['u_id'] = 2;
            $res['post_time'] = $data['post_time'];
            Application::db()->table('lp_down_item')
                ->insert($res);
            Application::db()->commit();
            return true;
        } catch (Exception $e) {
            Application::db()->rollback();
            return $e->getMessage();
        }
    }

    public function getDownList()
    {
        return Application::db()
            ->table('lp_download')
            ->field('*')
            ->select();
    }

    public function orderVip($user){}

    public function getItem()
    {
        return Application::db()
            ->table('lp_download a')
            ->field('*')
            ->join('left join lp_down_item b on a.id = b.down_id')
            ->where('a.id = ' . Application::input('post.id'))
            ->find();
    }

}